{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
<title>客户资料查询</title>
<link href="{% static 'plugins/bootstrap.css' %}" rel="stylesheet">
<link href="{% static 'plugins/bootstrap-dashen.css' %}" rel="stylesheet">
<link href="{% static 'plugins/font-awesome.css' %}" rel="stylesheet">
<link href="{% static 'plugins/animate.css' %}" rel="stylesheet">
<link href="{% static 'plugins/bootstrap-datetimepicker.min.css' %}" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
<div class="container">
{% include 'header.html' %}
	<div class="row"> 
	<div class="col-md-3 wow fadeInLeft">
		<div class="page-header">
    		<h1>客户资料查询</h1>
		</div>
		<form name="ziliaoQueryForm" id="ziliaoQueryForm" action="{% url 'Ziliao:frontUserList' %}" class="mar_t15" method="post">
			 {% csrf_token %}
			<div class="form-group">
				<label for="ziliaoName">资料名称:</label>
				<input type="text" id="ziliaoName" name="ziliaoName" value="{{ ziliaoName }}" class="form-control" placeholder="请输入资料名称">
			</div>
            <div class="form-group" style="display:none;">
            	<label for="userObj_user_name">上传客户：</label>
                <select id="userObj_user_name" name="userObj.user_name" class="form-control">
                	<option value="">不限制</option>
                    {% for userInfo in userInfos %}
                        {% if userInfo.user_name == userObj_user_name %}
                             <option value="{{ userInfo.user_name }}" selected>{{ userInfo.name }}</option>
                        {% else %}
                            <option value="{{ userInfo.user_name }}">{{ userInfo.name }}</option>
                        {% endif %}
                    {% endfor %}
 			</select>
            </div>
			<div class="form-group">
				<label for="upTime">上传时间:</label>
				<input type="text" id="upTime" name="upTime" class="form-control"  placeholder="请选择上传时间" value="{{ upTime }}" onclick="SelectDate(this,'yyyy-MM-dd')" />
			</div>
			<div class="form-group">
				<label for="shenHeState">审核状态:</label>
				<input type="text" id="shenHeState" name="shenHeState" value="{{ shenHeState }}" class="form-control" placeholder="请输入审核状态">
			</div>
			<div class="form-group">
				<label for="shenHeRen">审核人:</label>
				<input type="text" id="shenHeRen" name="shenHeRen" value="{{ shenHeRen }}" class="form-control" placeholder="请输入审核人">
			</div>
			<div class="form-group">
				<label for="shenHeTime">审核时间:</label>
				<input type="text" id="shenHeTime" name="shenHeTime" class="form-control"  placeholder="请选择审核时间" value="{{ shenHeTime }}" onclick="SelectDate(this,'yyyy-MM-dd')" />
			</div>
            <input type=hidden name=currentPage value="{{ currentPage }}" />
            <button type="submit" class="btn btn-primary">查询</button>
        </form>
	</div>

		<div class="col-md-9 wow fadeInDown" data-wow-duration="0.5s">
			<div>
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
			    	<li><a href="{% url 'Index:index' %}">首页</a></li>
			    	<li role="presentation" class="active"><a href="#ziliaoListPanel" aria-controls="ziliaoListPanel" role="tab" data-toggle="tab">客户资料列表</a></li>
			    	<li role="presentation" ><a href="{% url 'Ziliao:frontAdd' %}" style="display:none;">添加客户资料</a></li>
				</ul>
			  	<!-- Tab panes -->
			  	<div class="tab-content">
				    <div role="tabpanel" class="tab-pane active" id="ziliaoListPanel">
				    		<div class="row">
				    			<div class="col-md-12 top5">
				    				<div class="table-responsive">
				    				<table class="table table-condensed table-hover">
				    					<tr class="success bold"><td>序号</td><td>资料编号</td><td>资料名称</td><td>资料文件</td><td>上传客户</td><td>上传时间</td><td>审核状态</td><td>审核人</td><td>审核时间</td><td>信用积分</td><td>操作</td></tr>
                                        {% for ziliao in ziliaos_page %}
 										<tr>
 											<td>{{ startIndex|add:forloop.counter }}</td>
 											<td>{{ ziliao.ziliaoId }}</td>
 											<td>{{ ziliao.ziliaoName }}</td>
 											<td>
                        {%  if ziliao.ziliaoFile == 'file/NoFile.jpg' %}
                            暂无文件
                        {% else %}
                            <a href='{{ziliao.ziliaoFile.url }}' target='_blank'>{{ ziliao.ziliaoFile }}</a>
                        {% endif %}
 											</td>
 											<td>{{ ziliao.userObj.name }}</td>
 											<td>{{ ziliao.upTime }}</td>
 											<td>{{ ziliao.shenHeState }}</td>
 											<td>{{ ziliao.shenHeRen }}</td>
 											<td>{{ ziliao.shenHeTime }}</td>
 											<td>{{ ziliao.xyjf }}</td>
 											<td>
 												<a href="{% url 'Ziliao:frontShow' ziliao.ziliaoId  %}"><i class="fa fa-info"></i>&nbsp;查看</a>&nbsp;
 												<a href="#" onclick="ziliaoEdit('{{ ziliao.ziliaoId }}');" style="display:none;"><i class="fa fa-pencil fa-fw"></i>编辑</a>&nbsp;
 												<a href="#" onclick="ziliaoDelete('{{ ziliao.ziliaoId }}');" style="display:none;"><i class="fa fa-trash-o fa-fw"></i>删除</a>
 											</td> 
 										</tr>
 										{% endfor %}
				    				</table>
				    				</div>
				    			</div>
				    		</div>

				    		<div class="row">
					            <div class="col-md-12">
						            <nav class="pull-left">
						                <ul class="pagination">
						                    <li><a href="#" onclick="GoToPage({{ currentPage|add:-1 }},{{ totalPage }}>);" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
                                            {% for page in pageList %}
                                            {% if currentPage == page %}
						                        <li class="active"><a href="#"  onclick="GoToPage({{ page }},{{ totalPage }});">{{ page }}</a></li>
						                    {% else %}
                                                <li><a href="#"  onclick="GoToPage({{ page }},{{ totalPage }});">{{ page }}</a></li>
                                            {% endif %}
                                            {% endfor %}
						                    <li><a href="#" onclick="GoToPage({{ currentPage|add:1 }},{{ totalPage }});"><span aria-hidden="true">&raquo;</span></a></li>
						                </ul>
						            </nav>
						            <div class="pull-right" style="line-height:75px;" >共有{{ recordNumber }}条记录，当前第{{ currentPage }}/{{ totalPage }} 页</div>
					            </div>
				            </div> 
				    </div>
				</div>
			</div>
		</div>
		</div>
	</div> 
<div id="ziliaoEditDialog" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><i class="fa fa-edit"></i>&nbsp;客户资料信息编辑</h4>
      </div>
      <div class="modal-body" style="height:450px; overflow: scroll;">
      	<form class="form-horizontal" name="ziliaoEditForm" id="ziliaoEditForm" enctype="multipart/form-data" method="post"  class="mar_t15">
		    {% csrf_token %}
		  <div class="form-group">
			 <label for="ziliao_ziliaoId_edit" class="col-md-3 text-right">资料编号:</label>
			 <div class="col-md-9"> 
			 	<input type="text" id="ziliao_ziliaoId_edit" name="ziliao.ziliaoId" class="form-control" placeholder="请输入资料编号" readOnly>
			 </div>
		  </div> 
		  <div class="form-group">
		  	 <label for="ziliao_ziliaoName_edit" class="col-md-3 text-right">资料名称:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="ziliao_ziliaoName_edit" name="ziliao.ziliaoName" class="form-control" placeholder="请输入资料名称">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_ziliaoFile_edit" class="col-md-3 text-right">资料文件:</label>
		  	 <div class="col-md-9">
			    <a id="book_bookFileA" target="_blank"></a><br/>
			    <input id="ziliao_ziliaoFile" name="ziliao.ziliaoFile" type="file" size="50" />
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_userObj_user_name_edit" class="col-md-3 text-right">上传客户:</label>
		  	 <div class="col-md-9">
			    <select id="ziliao_userObj_user_name_edit" name="ziliao.userObj.user_name" class="form-control">
                    {% for userInfo in userInfos %}
                        <option value="{{ userObj.user_name }}">{{ userObj.name }}</option>
                    {% endfor %}
			    </select>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_upTime_edit" class="col-md-3 text-right">上传时间:</label>
		  	 <div class="col-md-9">
                <div class="input-group date ziliao_upTime_edit col-md-12" data-link-field="ziliao_upTime_edit">
                    <input class="form-control" id="ziliao_upTime_edit" name="ziliao.upTime" size="16" type="text" value="" placeholder="请选择上传时间" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_shenHeState_edit" class="col-md-3 text-right">审核状态:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="ziliao_shenHeState_edit" name="ziliao.shenHeState" class="form-control" placeholder="请输入审核状态">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_shenHeRen_edit" class="col-md-3 text-right">审核人:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="ziliao_shenHeRen_edit" name="ziliao.shenHeRen" class="form-control" placeholder="请输入审核人">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_shenHeTime_edit" class="col-md-3 text-right">审核时间:</label>
		  	 <div class="col-md-9">
                <div class="input-group date ziliao_shenHeTime_edit col-md-12" data-link-field="ziliao_shenHeTime_edit">
                    <input class="form-control" id="ziliao_shenHeTime_edit" name="ziliao.shenHeTime" size="16" type="text" value="" placeholder="请选择审核时间" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="ziliao_xyjf_edit" class="col-md-3 text-right">信用积分:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="ziliao_xyjf_edit" name="ziliao.xyjf" class="form-control" placeholder="请输入信用积分">
			 </div>
		  </div>
		</form> 
	    <style>#ziliaoEditForm .form-group {margin-bottom:5px;}  </style>
      </div>
      <div class="modal-footer"> 
      	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      	<button type="button" class="btn btn-primary" onclick="ajaxZiliaoModify();">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% include 'footer.html' %}
<script src="{% static 'plugins/jquery.min.js' %}"></script>
<script src="{% static 'plugins/bootstrap.js' %}"></script>
<script src="{% static 'plugins/wow.min.js' %}"></script>
<script src="{% static 'plugins/bootstrap-datetimepicker.min.js' %}"></script>
<script src="{% static 'plugins/locales/bootstrap-datetimepicker.zh-CN.js' %}"></script>
<script type="text/javascript" src="{% static 'js/jsdate.js' %}"></script>
<script>
/*跳转到查询结果的某页*/
function GoToPage(currentPage,totalPage) {
    if(currentPage==0) return;
    if(currentPage>totalPage) return;
    document.ziliaoQueryForm.currentPage.value = currentPage;
    document.ziliaoQueryForm.submit();
}

/*可以直接跳转到某页*/
function changepage(totalPage)
{
    var pageValue=document.ziliaoQueryForm.pageValue.value;
    if(pageValue>totalPage) {
        alert('你输入的页码超出了总页数!');
        return ;
    }
    document.ziliaoQueryForm.currentPage.value = pageValue;
    documentziliaoQueryForm.submit();
}

/*弹出修改客户资料界面并初始化数据*/
function ziliaoEdit(ziliaoId) {
	$.ajax({
		url :  '/Ziliao/update/' + ziliaoId,
		type : "get",
		dataType: "json",
		success : function (ziliao, response, status) {
			if (ziliao) {
				$("#ziliao_ziliaoId_edit").val(ziliao.ziliaoId);
				$("#ziliao_ziliaoName_edit").val(ziliao.ziliaoName);
				$("#ziliao_ziliaoFileA").text(decodeURIComponent(ziliao.ziliaoFile));
				$("#ziliao_ziliaoFileA").attr("href", ziliao.ziliaoFile);
				$.ajax({
					url: "{% url 'UserInfo:listAll' %}",
					type: "get",
					success: function(userInfos,response,status) { 
						$("#ziliao_userObj_user_name_edit").empty();
						var html="";
		        		$(userInfos).each(function(i,userInfo){
		        			html += "<option value='" + userInfo.user_name + "'>" + userInfo.name + "</option>";
		        		});
		        		$("#ziliao_userObj_user_name_edit").html(html);
		        		$("#ziliao_userObj_user_name_edit").val(ziliao.userObjPri);
					}
				});
				$("#ziliao_upTime_edit").val(ziliao.upTime);
				$("#ziliao_shenHeState_edit").val(ziliao.shenHeState);
				$("#ziliao_shenHeRen_edit").val(ziliao.shenHeRen);
				$("#ziliao_shenHeTime_edit").val(ziliao.shenHeTime);
				$("#ziliao_xyjf_edit").val(ziliao.xyjf);
				$('#ziliaoEditDialog').modal('show');
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*删除客户资料信息*/
function ziliaoDelete(ziliaoId) {
    var csrf = $('input[name="csrfmiddlewaretoken"]').val();
	if(confirm("确认删除这个记录")) {
		$.ajax({
			type : "POST",
			url : "/Ziliao/deletes",
			data : {
				ziliaoIds : ziliaoId,
                "csrfmiddlewaretoken": csrf
			},
			success : function (obj) {
				if (obj.success) {
					alert("删除成功");
					$("#ziliaoQueryForm").submit();
					//location.href= basePath + "Ziliao/frontlist";
				}
				else 
					alert(obj.message);
			},
		});
	}
}

/*ajax方式提交客户资料信息表单给服务器端修改*/
function ajaxZiliaoModify() {
	$.ajax({
		url :   '/Ziliao/update/' + $("#ziliao_ziliaoId_edit").val(),
		type : "post",
		dataType: "json",
		data: new FormData($("#ziliaoEditForm")[0]),
		success : function (obj, response, status) {
            if(obj.success){
                alert("信息修改成功！");
                $("#ziliaoQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();

    /*上传时间组件*/
    $('.ziliao_upTime_edit').datetimepicker({
    	language:  'zh-CN',  //语言
    	format: 'yyyy-mm-dd hh:ii:ss',
    	weekStart: 1,
    	todayBtn:  1,
    	autoclose: 1,
    	minuteStep: 1,
    	todayHighlight: 1,
    	startView: 2,
    	forceParse: 0
    });
    /*审核时间组件*/
    $('.ziliao_shenHeTime_edit').datetimepicker({
    	language:  'zh-CN',  //语言
    	format: 'yyyy-mm-dd hh:ii:ss',
    	weekStart: 1,
    	todayBtn:  1,
    	autoclose: 1,
    	minuteStep: 1,
    	todayHighlight: 1,
    	startView: 2,
    	forceParse: 0
    });
})
</script>
</body>
</html>

